//  this library.
import 'package:flutter/material.dart';
import 'package:hktk_app/util/view_util.dart';

/// 意见反馈页面图片上传提示样式
class ImageUploadDecoration extends Decoration {
  @override
  BoxPainter createBoxPainter([VoidCallback? onChanged]) {
    return _ImageUploadPainter();
  }
}

class _ImageUploadPainter extends BoxPainter {
  @override
  void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
    var size = configuration.size!;

    // 起始坐标
    double startX = offset.dx;
    double startY = offset.dy;
    // 最右边x坐标
    double rightX = startX + size.width;
    // 最顶部y坐标
    double bottomY = startY + size.height;

    // 绘制路径
    Path path = _getPaht(
        startX: startX, startY: startY, rightX: rightX, bottomY: bottomY);

    // 画笔
    Paint paint = Paint()
      ..color = colorGrey2
      ..style = PaintingStyle.fill;

    // 绘制
    canvas.drawPath(path, paint);
  }

  /// 路径绘制方法
  Path _getPaht({
    required double startX,
    required double startY,
    required double rightX,
    required double bottomY,
  }) {
    // 圆角
    double radius = 10;
    // 三角位置，距离最左边宽度
    double triangleLeft = 72;
    double triangleLeft1 = 80;
    double triangleLeft2 = 88;
    // 三角高度
    double triangleHeight = 8;

    bottomY = bottomY - triangleHeight;

    Path path = Path();

    path.moveTo(startX + radius, startY);
    path.quadraticBezierTo(startX, startY, startX, startY + radius);
    path.lineTo(startX, bottomY - radius);
    path.quadraticBezierTo(startX, bottomY, startX + radius, bottomY);
    path.lineTo(startX + triangleLeft, bottomY);
    path.lineTo(startX + triangleLeft1, bottomY + triangleHeight);
    path.lineTo(startX + triangleLeft2, bottomY);
    path.lineTo(rightX - radius, bottomY);
    path.quadraticBezierTo(rightX, bottomY, rightX, bottomY - radius);
    path.lineTo(rightX, startY + radius);
    path.quadraticBezierTo(rightX, startY, rightX - radius, startY);
    path.close();

    return path;
  }
}
